import pymysql
conn=None
cursor_delete=None
cursor_select=None
try:
    conn=pymysql.connect(host="localhost",port=3306,user="root",password="123456",
                         database="api_pymysql_database",charset="utf8")
    # 创建游标对象
    cursor_delete=conn.cursor()
    cursor_select=conn.cursor()


    # 执行Sql语句
    # 修改数据
    sql_insert="delete from areas where atitle='周口市';"
    cursor_delete.execute(sql_insert)
    # 提交/回滚事务
    conn.commit()
    conn.rollback()
    # 查询数据
    cursor_select.execute("select * from areas; ")
    data =cursor_select.fetchall()
    print(data)
except Exception as error:
    print("操作数据失败:", error)
    #若失败则在此做回滚事务
    conn.rollback()
finally:
    cursor_delete.close()
    cursor_select.close()
    conn.close()